package com.javaweb.mapper;

import com.javaweb.entity.Room;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RoomMapper {
    @Insert("insert into room(room_name, intro, creator_id, create_time) values(#{roomName}, #{intro}, #{creatorId}, now())")
    void add(Room room);

    @Select("select * from room")
    List<Room> listAll();

    @Select("select * from room where creator_id = #{userId}")
    List<Room> listByUserId(Integer userId);

    @Select("select * from room where id = #{id}")
    Room findById(Integer id);

    @Update("update room set room_name = #{roomName}, intro = #{intro} where id = #{id}")
    void update(Room room);

    @Select("select * from room where room_name = #{roomName}")
    Room findByRoomName(String roomName);
}
